package com.sbwebsocket.core.config;

import com.sbwebsocket.core.redis.RedisModeUtil;
import com.sbwebsocket.core.redis.config.RedisConfig;
import com.sbwebsocket.core.service.ClientManager;
import com.sbwebsocket.core.service.MasterServerWork;
import com.sbwebsocket.core.service.impl.ClientManagerImpl;
import com.sbwebsocket.core.util.SpringUtil;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;

/**
 * @Auther: GSJ
 * @Date: 2022/2/16
 * @Description:
 * @version: 1.0
 */
@Configuration
public class DefaultSbWebsocketAutoConfig {

//    @ConditionalOnExpression("'${ws.messageQueueChoose}'.equals('redis')")
//    @Bean
//    public MessageQueueAdapter  redisConfig(){
//        System.out.println("22222");
//        return new RedisConfig();
//    }

    @ConditionalOnMissingBean(SpringUtil.class)
    @Bean
    SpringUtil springUtil() {
        return new SpringUtil();
    }
    
    @Bean
    ClientManager clientManager(){
        return new ClientManagerImpl();
    }
    
    @Bean
    MasterServerWork masterServerWork(){
        return new MasterServerWork();
    }

    @Bean
    @Order(999)
    WsBootStrapStart wsBootStrapStart(){
        return new WsBootStrapStart();
    }
    
    @ConditionalOnExpression("'${ws.messageQueueChoose}'.equals('redis')")
    @Configuration
    public static class ReidsAutoConfig extends RedisConfig {
        
        @Bean
        RedisModeUtil redisModeUtil(){
            return new RedisModeUtil();
        }
    }


    @Configuration
    public static class WebSocketAutoConfig extends WebSocketConfig {

    }

    @Configuration
    public static class WsAppAutoConfig extends WsAppConfig {

    }

    @Configuration
    public static class CorsAutoConfig extends CorsConfig {

    }


}
